package cn.com.api.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.api.entity.ApiDingDan;
import cn.com.api.entity.ApiT_juan_tj;
import cn.com.api.mapper.ApiJuanTJMapper;
import cn.com.api.service.ApiT_juan_tjService;
import cn.com.api.service.impl.base.T_juan_tjServiceImplBase;
import cn.com.api.service.impl.base.T_logerpServiceImplBase;

@Service
public class ApiT_juan_tjServiceImpl extends T_juan_tjServiceImplBase implements ApiT_juan_tjService {
	@Autowired
	private ApiJuanTJMapper apiJuanTJMapper;

	/**
	 * 订单确认取消 判断订单是否使用优惠券， 使用了，则恢复优惠券的使用，使其可使用 未使用，则不做修改
	 * */
	@Transactional
	@Override
	public void recoveryJuanOnDingDan(ApiDingDan dingDan) {
		if (dingDan != null) {
			Integer is_quan = dingDan.getIs_quan();
			if (is_quan != null && 1 == is_quan) {// 使用了优惠券
				String u_id = dingDan.getU_id();
				Integer quan_id = dingDan.getQuan_id();
				ApiT_juan_tj juan_tj = apiJuanTJMapper
						.selectApiT_juan_tjByUidAndJid(u_id, quan_id);
				Integer count = juan_tj.getCount()+1;
				juan_tj.setCount(count);
				juan_tj.setEnable(0);// 优惠券修改为未使用
				apiJuanTJMapper.updateApiT_juan_tj(juan_tj);
			}
		}
	}

}
